//
//  ZBPlatformAppDelegate.m
//  Pods
//
//  Created by xzb on 2018/10/9.
//

#import "ZBPlatformAppDelegate.h"
#import "ZBAppLifecycleManager.h"

@implementation ZBPlatformAppDelegate

#pragma mark -

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [ZBAppLifecycleManager registerAllLib];
    return [[ZBAppLifecycleManager sharedInstance] application:application
                                willFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return [[ZBAppLifecycleManager sharedInstance] application:application
                                 didFinishLaunchingWithOptions:launchOptions];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //注册远程通知
    [application registerForRemoteNotifications];
    [[ZBAppLifecycleManager sharedInstance] application:application
                    didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)pToken
{
    [[ZBAppLifecycleManager sharedInstance] application:application
       didRegisterForRemoteNotificationsWithDeviceToken:pToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    [[ZBAppLifecycleManager sharedInstance] application:application
       didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [[ZBAppLifecycleManager sharedInstance] application:application
                           didReceiveRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [[ZBAppLifecycleManager sharedInstance] application:application
                            didReceiveLocalNotification:notification];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    return [[ZBAppLifecycleManager sharedInstance] application:application
                                          continueUserActivity:userActivity
                                            restorationHandler:restorationHandler];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationDidEnterBackground:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationDidBecomeActive:application];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationWillResignActive:application];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationWillTerminate:application];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationDidReceiveMemoryWarning:application];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [[ZBAppLifecycleManager sharedInstance] application:application
                                                       openURL:url
                                             sourceApplication:sourceApplication
                                                    annotation:annotation];
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler __IOS_AVAILABLE(9.0)
{
    [[ZBAppLifecycleManager sharedInstance] application:application
                           performActionForShortcutItem:shortcutItem
                                      completionHandler:completionHandler];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[ZBAppLifecycleManager sharedInstance] applicationWillEnterForeground:application];
}


///后台自动更新
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[ZBAppLifecycleManager sharedInstance] application:application
                      performFetchWithCompletionHandler:completionHandler];
}

///静默推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[ZBAppLifecycleManager sharedInstance] application:application
                           didReceiveRemoteNotification:userInfo
                                 fetchCompletionHandler:completionHandler];
}

#pragma mark - response

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    [[ZBAppLifecycleManager sharedInstance] remoteControlReceivedWithEvent:event];
}


@end
